import React, {PropTypes} from 'react';
import {withRouter} from 'react-router';
import {Button} from 'antd';
import {context} from './index';

@withRouter
@context({
    routes: PropTypes.array
})
export default class Query extends React.Component {
    back = () => {
        this.props.router.goBack();
    }

    btn2Click = () => {
        this.props.onState('new');
    }

    render() {
        const {btn2Text, btnsLeft, btnsRight} = this.props;
        const btn2 = btn2Text
            ? (<Button type="primary" onClick={this.btn2Click}>{this.props.btn2Text}</Button>)
            : '';

        return (
            <div className="line padding-t-b titleinfo">
                <span className="h2">{this.props.title}</span>
                {btnsLeft}
                <div className="floatright">
                    <Button.Group>
                        {btnsRight}
                        {btn2}
                        <Button onClick={this.back} className="icon"><i className="iconfont icon-back"/>返回</Button>
                    </Button.Group>
                </div>
            </div>
        );
    }
}
